function addBinary(a: string, b: string): string {
    let sum: any = [];
    let lang: any = (a.length > b.length) ?Array.from(a):Array.from(b);
    let short: any =  (a.length > b.length) ?Array.from(b):Array.from(a);  
    for(let i=0;i<lang.length;i++){
        lang[i] = parseInt(lang[i]);
    }
    for(let i=0;i<short.length;i++){
        short[i] = parseInt(short[i]);
    }     
    sum = lang;
    for(let k=0, i=lang.length-1,j=short.length-1 ; j>=0 ;k++,j--,i--){
        // sum.push(lang[i] + short[j])
        sum[i] = lang[i] + short[j];
        if(sum[i] === 2 || sum[i] > 2){
            if(sum[i] === 2){
                sum[i]=0;
                if( (i-1) >= 0 ){//不能判断值，只能判断下标，因为字可能为0 
                    sum[i-1]+=1;
                }else{
                    sum.unshift(1);
                }
            }
            if(sum[i] > 2){
                sum[i] = 1;
                if( (i-1) >= 0 ){//不能判断值，只能判断下标，因为字可能为0 
                    sum[i-1]+=1;
                }else{
                    sum.unshift(1);
                }
            }
        }
    }
    console.log(sum);
    //判断头部为2的情况
    for(let i = sum.length-1; i >= 0 ;i--){
        if(sum[i] === 2){
            sum[i]=0;
            if( (i-1) >= 0 ){//不能判断值，只能判断下标，因为字可能为0 
                sum[i-1]+=1;
            }else{
                sum.unshift(1);
            }
        }
    }

    console.log(sum);
    sum = sum.toString();
    sum = sum.replaceAll(",","");
    return sum;
};

// let a = "11", b = "1";
// let a = "1010", b = "1011";
// let a = "1", b = "111";
let a = "1111", b = "1111";
console.log(addBinary(a,b));